<#+
void SaveInNewFile(string fileName)
{
    // rcupration du dossier dans lequel s'excute le template
    string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);
    if (string.IsNullOrWhiteSpace(templateDirectory)) throw new DirectoryNotFoundException();
    string outputFilePath = Path.Combine(templateDirectory, fileName);
    // criture dans le fichier de code tout le code gnr jusque l par le template 
    File.WriteAllText(outputFilePath, this.GenerationEnvironment.ToString()); 
    // on supprime le code gnr jusque ici pour qu'il n'apparaisse pas dans le fichier suivant
    GenerationEnvironment.Remove(0, this.GenerationEnvironment.Length);
    IServiceProvider hostServiceProvider = (IServiceProvider)this.Host;
    // rcupration d'un objet permettant de manipuler la solution sous Visual Studio
    DTE dte = (DTE)hostServiceProvider.GetService(typeof(DTE));
    // rcupration d'une rfrance au projet dans lequel se trouve le template
    ProjectItem templateProjectItem = dte.Solution.FindProjectItem(Host.TemplateFile);
    // ajout du fichier dans le projet
    templateProjectItem.ProjectItems.AddFromFile(outputFilePath);  
}
#>
